<!DOCTYPE html>
<html lang="zh">
<head>
    #@header();
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">

        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>完整验证表单</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="imgForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">logo图：</label>
                            <div class="col-sm-8">
                                <input id="imgpath" name="imgpath" class="form-control" type="file">
                                <img id="showImg" src="#(prj)#(config.logo??)" height="80px">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">登录背景：</label>
                            <div class="col-sm-8">
                                <input id="imgpath1" name="imgpath1"  class="form-control" type="file">
                                <img id="showImg1" src="#(prj)#(config.login_bg??)" height="80px">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">ico图：</label>
                            <div class="col-sm-8">
                                <input id="imgpath2" name="imgpath2"  class="form-control" type="file">
                                <img id="showImg2" src="#(prj)#(config.ico??)" height="80px">
                            </div>
                        </div>

                        #if(permission != null && permission.get('update')!= null )
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <a class="btn btn-primary" onclick="submit2()">提交</a>
                            </div>
                        </div>
                        #end
                    </form>
                </div>
            </div>
        </div>

        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>简单示例</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="textForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">系统名：</label>
                            <div class="col-sm-8">
                                <input name="sys_name" type="text" value="#(config.sys_name??)" class="form-control" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">核心理念：</label>
                            <div class="col-sm-8">
                                <input name="core_idea" type="text" value="#(config.core_idea??)" class="form-control" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">商标版权等：</label>
                            <div class="col-sm-8">
                                <input name="copyright" type="text" value="#(config.copyright??)" class="form-control" >
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">管理员手机：</label>
                            <div class="col-sm-8">
                                <input name="mobile" type="text" value="#(config.mobile??)" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">项目说明：</label>
                            <div class="col-sm-8">
                                <textarea name="prj_desc" class="form-control" style="width: 512px;height: 160px">#(config.prj_desc??)</textarea>
                                <span style="color: red">注：分号换行</span>
                            </div>
                        </div>
                        #if(permission != null && permission.get('update')!= null )
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <a class="btn btn-primary" onclick="submit1()">提交</a>
                            </div>
                        </div>
                        #end
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

#@footer();
<script type="text/javascript">
    $(function(){
/*        $("#imgForm").validate({
            rules: {
                imgpath: {
                    required: true,
                },
                imgpath1: {
                    required: true,
                },
                imgpath2: {
                    required: true,
                },
            },
            messages: {
                imgpath:"请上传logo图",
                imgpath1:"请上传登录背景图",
                imgpath2:"请上传ico图",
            }
        });*/

        $("#textForm").validate({
            rules: {
                sys_name: {required: true, minlength: 2},
                core_idea: {required: true, minlength: 4},
                copyright: {required: true, minlength: 5},
                mobile: {required: true, minlength: 7},
                prj_desc: {required: true, minlength: 2},
            },
            messages: {
                sys_name: "请输入系统名称",
                core_idea: "请输入核心理念",
                copyright: "请输入商标版权",
                mobile: "请输入管理员手机号",
                prj_desc: "请输入项目说明",
            }
        });

        //图片回显
        $("#imgpath").bind("change", function () {
            $("#showImg").attr("src", window.URL.createObjectURL($("#imgpath").get(0).files[0]))
        })

        $("#imgpath1").bind("change", function () {
            $("#showImg1").attr("src",  window.URL.createObjectURL($("#imgpath1").get(0).files[0]))
        })

        $("#imgpath2").bind("change", function () {
            $("#showImg2").attr("src", window.URL.createObjectURL($("#imgpath2").get(0).files[0]))
        })
    });

    function submit1() {
        if ($.validate.form("textForm")) {
            edit1();
        }
    }

    function edit1() {
        var formData = new FormData();
        formData.append("config.sys_name",$("input[name='sys_name']").val())
        formData.append("config.core_idea",$("input[name='core_idea']").val())
        formData.append("config.copyright",$("input[name='copyright']").val())
        formData.append("config.mobile",$("input[name='mobile']").val())
        formData.append("config.prj_desc",$("textarea[name='prj_desc']").val())
        formData.append("config.id",'#(config.id??)')

        $.ajax({
            url:"#(prj)/admin/config/update",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallbackMsg(data.msg);
            }
        });
    }


    function submit2() {
        if ($.validate.form("imgForm")) {
            edit2();
        }
    }

    function edit2() {
        var formData = new FormData();
        formData.append("uploadpath",$("#imgpath").get(0).files[0]);
        formData.append("uploadpath1",$("#imgpath1").get(0).files[0])
        formData.append("uploadpath2",$("#imgpath2").get(0).files[0])
        formData.append("config.id",'#(config.id??)')

        $.ajax({
            url:"#(prj)/admin/config/update",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallbackMsg(data.msg);
            }
        });
    }
</script>
</body>
</html>
